#define quickread
#ifdef quickread
#include <cstdio> 
template <typename T>
inline void read(T& x)
{
    int c=getchar(), f=1; x=0;
    while(c<'0'||'9'<c) {if(c=='-') f=-1; c=getchar();}
    while('0'<=c&&c<='9') 
        x=(x<<3)+(x<<1)+c-'0', c=getchar();
    x*=f;
}
template <typename T>
inline void quickwrite(T x)
{
    if(x<0) putchar('-'), x*=-1;
    if(x>=10) quickwrite(x/10);
    putchar(x%10+'0');
}
#else 
#include <iostream>
#endif
#include <algorithm>
using namespace std;
#define DEBUG
/*
* a>b时 +1只能让a更大，当a为奇数时^1实现a-1
* a<=b时，结合^1(a为偶数时) +1实现
*/
int a, b, x, y;
long long ans;

void init()
{
    read(a), read(b), read(x), read(y);
    ans=0;
}

void solve()
{
    init();
    if(a>b) {quickwrite((a^1)==b?y:-1); puts(""); return;}
    long long d=b-a, d1=(b+1>>1)-(a+1>>1); //d1:a->b之间通过^代替+实现的步数
    // ans=(d/2)*min(x, y)+(d+1)/2*x;
    // if(a%2) ans=1ll*(d/2)*min(x, y)+1ll*(d+1)/2*x;
    // else ans=1ll*(d+1/2)*min(x, y)+1ll*(d)/2*x;
    ans=y>x?1ll*d*x:1ll*(d-d1)*x+1ll*d1*y;
    quickwrite(ans); puts("");
}

// #undef DEBUG
signed main()
{
    #ifdef DEBUG
        freopen("../in.txt", "r", stdin);
        freopen("../out.txt", "w", stdout);
    #endif
    #ifndef quickread
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    #endif

    int T=1; scanf("%d", &T);
    while(T--) 
    {
        solve();
    }
    return 0;
}
